<!--
 * @Descripttion: 
 * @version: 
 * @Author: 彭勃
 * @Date: 2023-03-29 13:31:49
 * @LastEditors: sueRimn
 * @LastEditTime: 2023-04-06 15:18:39
-->
<template>
  <EnteringForm
    ref="enteringForm"
    v-bind="dialog"
		width="60%"
    @close="close"
    @submit="submit"
  >
    <el-form ref="formRef" :model="queryParams" :rules="rules" label-width="120px">
      <el-row type="flex" style="flex-wrap: wrap">
				<el-col :xs="24" :sm="12" :lg="12">
          <el-form-item label="店铺名称:" prop="name">
            <el-input
              v-model.trim="queryParams.name"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :lg="12">
          <el-form-item label="手机号:" prop="mobile">
            <el-input
              v-model.trim="queryParams.mobile"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :lg="12">
          <el-form-item label="身份证:" prop="idCard">
            <el-input
              v-model.trim="queryParams.idCard"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :lg="12">
          <el-form-item label="真实姓名:" prop="realName">
            <el-input
              v-model.trim="queryParams.realName"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :lg="12">
          <el-form-item label="银行卡号:" prop="bankAccount">
            <el-input
              v-model.trim="queryParams.bankAccount"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :lg="12">
          <el-form-item label="银行预留手机号:" prop="bankMobile">
            <el-input
              v-model.trim="queryParams.bankMobile"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :lg="12">
          <el-form-item label="银行名称:" prop="bankName">
            <el-input
              v-model.trim="queryParams.bankName"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :lg="12">
          <el-form-item label="标签:" prop="tag">
            <el-input
              v-model.trim="queryParams.tag"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :lg="24">
          <!-- 22--{{ queryParams.avatar }} -->
          <el-form-item label="用户头像:" prop="avatar">
            <ImageUpload
              v-model="queryParams.avatar"
              :limit="1"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </EnteringForm>
</template>

<script setup>
import { getCurrentInstance, reactive, ref } from "vue";
import { ElMessage } from "element-plus";
import { listPage, info } from '@/api/order/seller.js'

const { proxy } = getCurrentInstance()
const emit = defineEmits(["success"]);
const dialogType = ref('')
const dialog = reactive({
  visible: false,
  title: "",
});
const rules = reactive({
  type: [{ required: true, message: "请选择", trigger: "change" }],
  sort: [{ required: true, message: "请输入", trigger: "blur" }],
  goodsName: [{ required: true, message: "请选择", trigger: "change" }],
  logo: [{ required: true, message: "请上传", trigger: "blur" }],
});
const queryParams = ref({})

function init(type, record){
	dialogType.value = type
	dialog.title='发货'
	dialog.visible = true
	// 如果是编辑，回显数据
	if(dialogType.value=='edit'){
		// queryParams.value = { ...record };
    getInfo(record)
	}
};

function getInfo(record){
  info(record).then(res=>{
    queryParams.value = res.data
  })
}

function close(){
  dialog.visible = false;
  proxy.$refs.formRef.resetFields();
	queryParams.value = {}
};
function submit() {
  proxy.$refs.formRef.validate((valid) => {
    if (valid) {
      let query = {
        ...queryParams
      }
      sendApi(query).then((res) => {
        if (res.code == 200) {
          ElMessage.success("发货成功");
          close();
          emit("success",'edit');
        } else {
          ElMessage.error(res.message || "发货失败");
        }
      });
    }
  });
}
defineExpose({ init });
</script>

<style scoped>
.v-enter-active,
.v-leave-active {
  transition: opacity 0.5s ease;
}

.v-enter-from,
.v-leave-to {
  opacity: 0;
}
</style>
